﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using eAssessment.questions;
using eAssessment.Classes.Lists;
using eAssessment.SPLinqLern;
using eAssessment.SPLinqPortal;
using Microsoft.SharePoint.Administration;
using System.Data;

namespace eAssessment.lists
{
    class ListAccessManager
    {

        public const string AssessmentActiveListName = "eAssessment - Assessment-Active";
        public const string MChoiceAnswerTemplateListName = "eAssessment - MChoiceAnswer-Templates";
        public const string QuestionTemplateListName = "eAssessment - Question-Templates";


        private SPWeb GetCurrentListWeb()
        {
            SPWeb thisWeb = SPContext.Current.Web;
            SPWebCollection webcollection = thisWeb.Site.AllWebs;
            return webcollection[0];
        }

        private SPWeb GetPortalWebFromLearnSite()
        {
            SPWebApplication app = SPContext.Current.Web.Site.WebApplication;
            SPSite portalsite = app.Sites["Websites/Portal"];
            return portalsite.AllWebs[0];
        }

        public int AddMultipleChoiceQuestionTemplate(string theme, string question)
        {
            QuestionListManager mgr = new QuestionListManager();
            return mgr.AddQuestionTemplate(theme,question,GetCurrentListWeb());
        }

        public int AddMultipleChoiceAnswerTemplate(string answer, bool isCorrect, int questionID)
        {
            MChoiceAnswerTemplateListManager mgr = new MChoiceAnswerTemplateListManager();
            return mgr.AddMultipleChoiceAnswerTemplate(answer, isCorrect, questionID, GetCurrentListWeb());
        }

        public MultipleChoiceQuestionTemplate GetMultipleChoiceQuestionTemplate(string id)
        {
            MChoiceQuestionTemplateListManager mgr = new MChoiceQuestionTemplateListManager();
            return mgr.GetMultipleChoiceQuestionTemplate(id, GetCurrentListWeb());
        }

        public List<AssessmentType> GetAssessmentActiveList()
        {
            AssessmentActiveListManager mgr = new AssessmentActiveListManager();
            return mgr.GetActiveAssessments(GetCurrentListWeb());
        }

        public QuestionTemplate GetQuestionTemplate(int id)
        {
            QuestionListManager mgr = new QuestionListManager();
            return mgr.GetQuestionTemplate(id, GetPortalWebFromLearnSite());
        }

        public DataTable GetQuestionTemplateDataTable(){
            QuestionListManager mgr = new QuestionListManager();
            return mgr.GetQuestionTemplateDataTable(GetPortalWebFromLearnSite());
        }
    }
}
